package com.xauto.pioneer.appuser.fragment;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.location.Poi;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapPoi;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.map.Polyline;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.search.core.SearchResult;
import com.baidu.mapapi.search.route.BikingRoutePlanOption;
import com.baidu.mapapi.search.route.BikingRouteResult;
import com.baidu.mapapi.search.route.DrivingRouteResult;
import com.baidu.mapapi.search.route.IndoorRouteResult;
import com.baidu.mapapi.search.route.MassTransitRouteResult;
import com.baidu.mapapi.search.route.OnGetRoutePlanResultListener;
import com.baidu.mapapi.search.route.PlanNode;
import com.baidu.mapapi.search.route.RoutePlanSearch;
import com.baidu.mapapi.search.route.TransitRouteResult;
import com.baidu.mapapi.search.route.WalkingRouteResult;
import com.baidu.mapapi.utils.DistanceUtil;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
import com.xauto.pioneer.appuser.MainActivity;
import com.xauto.pioneer.appuser.MyApplication;
import com.xauto.pioneer.appuser.R;
import com.xauto.pioneer.appuser.activity.LoginActivity;
import com.xauto.pioneer.appuser.activity.ParkingSiteActivity;
import com.xauto.pioneer.appuser.activity.mine.OrderDetailActivity;
import com.xauto.pioneer.appuser.activity.mine.balance.DepositBalanceActivity;
import com.xauto.pioneer.appuser.activity.takeCar.FoundCarActivity;
import com.xauto.pioneer.appuser.http.BaseLHttpHandler;
import com.xauto.pioneer.appuser.http.Constants;
import com.xauto.pioneer.appuser.http.LHttpLib;
import com.xauto.pioneer.appuser.interfaces.ConfigCallBack;
import com.xauto.pioneer.appuser.interfaces.DeviceOrderInfoCallBack;
import com.xauto.pioneer.appuser.interfaces.MemberCallBack;
import com.xauto.pioneer.appuser.model.BikingRouteOverlay;
import com.xauto.pioneer.appuser.model.ClientSetting;
import com.xauto.pioneer.appuser.model.ClientVersion;
import com.xauto.pioneer.appuser.model.DeviceOrderInfo;
import com.xauto.pioneer.appuser.model.JSONStatus;
import com.xauto.pioneer.appuser.model.Member;
import com.xauto.pioneer.appuser.model.ParkingSite;
import com.xauto.pioneer.appuser.model.Region;
import com.xauto.pioneer.appuser.util.DataCheckUtil;
import com.xauto.pioneer.appuser.util.DataLoadUtil;
import com.xauto.pioneer.appuser.util.OverlayManager;
import com.xauto.pioneer.appuser.util.PackageUtil;
import com.xauto.pioneer.appuser.util.PreferencesUtils;
import com.xauto.pioneer.appuser.util.StringUtils;
import com.xauto.pioneer.appuser.util.ToastUtil;
import com.xauto.pioneer.appuser.view.LoadingDialog;
import com.xauto.pioneer.appuser.view.ParkingSiteCarDialog;
import com.xauto.pioneer.appuser.view.ParkingSiteCarPopupWindow;
import com.xauto.pioneer.appuser.view.ParkingSiteNoCarDialog;
import com.xauto.pioneer.appuser.view.PromptDialog;

import net.tsz.afinal.FinalDb;
import net.tsz.afinal.FinalHttp;
import net.tsz.afinal.http.AjaxCallBack;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.xauto.pioneer.appuser.http.Constants.MARKER_LOADED;

/**
 * Created by lsx on 2018-03-16.
 */

public class MainFragment extends Fragment implements OnGetRoutePlanResultListener{
    public static boolean isForeground = false;
    public static final String TAG = Fragment.class.getSimpleName();

    MapView mMapView;
    @Bind(R.id.ivMainRoadStatus)
    ImageView ivMainRoadStatus;
    @Bind(R.id.location_image) ImageView locationImage;
//    @Bind(R.id.UserAuth)
    TextView UserAuth;
    @Bind(R.id.ivChat)
    ImageView ivChat;
    String telNumber="";
    private boolean isOpenRoadStatus = false;
    private DisplayImageOptions hasCarOptions;
    private DisplayImageOptions noCarOptions;

    /**************** 地图相关 ******************/
    private BaiduMap mBaiDuMap;
    /** 定位相关*/
    private LocationClient mLocClient;
    boolean isFirstLoc = true; // 是否首次定位
    /** 所有marker集合*/
    private List<OverlayOptions> overlayOptionsList;
    /** marker 操作管理*/
    private MyOverlayManager myOverlayManager;
    /** 定位成功后，返回的当前定位*/
    public static BDLocation bdLocation;
    public static LatLng currentLatLng;

    /** 取车网点*/
    private List<ParkingSite> parkingSiteList;
    /** 取车标注网点*/
    private List<ParkingSite> parkingMarkerList;
    /**提示框*/
    private PromptDialog promptDialog;
    /**当前地图左右距离*/
    private int currentDistance = 1000;
    private int MapCurrentDistance = 1000;
    /**返回所有取车列表*/
    public static int MapCurrentDistanceList =200000;
    Context mContext;

    private float currentZoom =18;
    private boolean isShowLoading = false;
    /**是否来自网点无车辆刷新*/
    private boolean  isRefreshLoad = false;
    /**当前刷新的网点id*/
    private String currentRefreshSiteNo = "";
    //当前城市是否开放
    private boolean isOpen = false;
    //当前第一次加载
    private boolean isFirstLoad = true;
    //最近网点的经纬度
    private LatLng EndLat;
    private LoadingDialog loadingDialog;
    String PakeId=null;
    //添加认证信息
    private Member member;
    ParkingSiteCarDialog carDialog;
    public static ParkingSiteCarPopupWindow carPopupWindow = null;
    //定义拦截状态
    private String device_notify_key=null;
    private String device_notify_key_order_no=null;
    RoutePlanSearch mSearch = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.ac_main, container, false);
        mContext = getActivity();
        imageLoader = ImageLoader.getInstance();
        setupView(view);
        ButterKnife.bind(this, view);
        return view;
    }

    private void setupView(View view) {
        mMapView = (MapView) view.findViewById(R.id.mapMain);
        initView();
        initData();
    }
    protected void initView() {
//        UserAuth.setVisibility(View.GONE);
        initTelNumber();

    }
    private void initTelNumber(){
        FinalDb finalDb = FinalDb.create(mContext);
        List<ClientSetting> client = finalDb.findAll(ClientSetting.class);
        if (client != null && client.size() >0){
            telNumber = client.get(client.size()- 1).getContact_number();
        }
    }
    protected void initData() {

        // 初始化搜索模块，注册事件监听
        mSearch = RoutePlanSearch.newInstance();
        mSearch.setOnGetRoutePlanResultListener(this);
        hasCarOptions = MyApplication.getDisplayImageOptions(mContext, 20, R.mipmap.ic_map_car_blue);
        noCarOptions = MyApplication.getDisplayImageOptions(mContext, 20, R.mipmap.ic_map_car_gray);
        loadNoFinishOrder();
        updateVersion();
        //获取当前用户认证信息
        member = DataCheckUtil.getMemberObj(mContext);
        initBaiDuMap();
        ((MainActivity)getActivity()).setCallback(new MainActivity.ParkingSiteCallback() {
            @Override
            public void setdata(int resultCode, int requestCode,Intent data) {
//                Log.e("TAG","resultcode2 = "+resultCode+" , requestCode = "+requestCode);
                if (resultCode == Activity.RESULT_OK && requestCode == 100){
                Log.e(TAG,"resultcode2 = "+resultCode+" , requestCode = "+requestCode);
                    ParkingSite parkingSite = (ParkingSite)data.getSerializableExtra("parkingSite");
                    Log.e(TAG,"data = "+parkingSite.toString());
                    takeCurrentBranch(parkingSite);
                }
            }
        });
    }

    @OnClick({R.id.ivChat,R.id.mapMain,R.id.ivMainTakeCarNearbyPoint,R.id.tvMainTakeCarPoint, R.id.ivMainRoadStatus,R.id.location_image,R.id.mainRefresh})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ivChat:
                //用intent启动拨打电话
                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+telNumber));
                startActivity(intent);
                break;
            case R.id.tvMainTakeCarPoint:
                //选择取车网点
                if (bdLocation != null){
                    Intent intent2 = new Intent(mContext, ParkingSiteActivity.class);
                    intent2.putExtra("longitude", String.valueOf(currentLatLng.longitude));
                    intent2.putExtra("latitude", String.valueOf(currentLatLng.latitude));
                    intent2.putExtra("distance", String.valueOf(MapCurrentDistanceList));
                    startActivityForResult(intent2,100);
                }else {
                    prompt("当前位置不可用，请先刷新界面");
                }
                break;
            case R.id.ivMainRoadStatus:
                //开启|关闭路况
                isOpenRoadStatus = !isOpenRoadStatus;
                ivMainRoadStatus.setImageResource(isOpenRoadStatus ? R.mipmap.ic_map_road_status : R.mipmap.ic_map_road_status_gray);
                // 开启交通图
                mBaiDuMap.setTrafficEnabled(isOpenRoadStatus);
                break;
            case R.id.location_image:
                //回归到我的位置34.275457
                setMyLocationToCenter(new LatLng(bdLocation.getLatitude(),bdLocation.getLongitude()),currentZoom);
                currentLatLng = new LatLng(bdLocation.getLatitude(),bdLocation.getLongitude());

                loadAll(false,"");
                break;
            case R.id.ivMainTakeCarNearbyPoint:
                //显示就近取车网点并绘制路线
                mBaiDuMap.clear();
                if(DataCheckUtil.isLogin(mContext)){
                    load(false,member.member_id);
                }
                else{
                    ToastUtil.showShort(mContext, "请先登录");
                    mContext.startActivity(new Intent(mContext, LoginActivity.class));
                }

                break;
            case R.id.mainRefresh:
                //刷新地图数据
//                mLocClient.requestLocation();// 请求 mLocClient.requestLocation()函数,会主动触发定位SDK内部定位逻辑，等待定位回调即可
                MyApplication.getInstance().mSpeechSynthesizer.speak("您的车辆信用使用金额已不足，请尽快充值，而不影响您继续使用车辆，谢谢您的支持。");
                isShowLoading = true;
                //load(false);
                loadAll(false,"");
                break;
        }
    }
    public static  void  popDismiss(){
        if(carPopupWindow!=null){
            if(carPopupWindow.isShowing()){
                carPopupWindow.dismiss();
            }
            carPopupWindow =null;
        }
    }
    /***
     * TOAST
     * @param msg
     */
    protected void prompt(String msg) {
        if(mContext != null) {
            ToastUtil.showShort(mContext, msg);
        }
    }
    /**
     * 设置我的位置到中心点
     */
    private void setMyLocationToCenter(LatLng latLng,float currentZoom){
        //设置当前位置到地图中间
        MapStatus mapStatus = new MapStatus.Builder().target(latLng).zoom(currentZoom).build();
        MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mapStatus);
        mBaiDuMap.setMapStatus(mMapStatusUpdate);

    }

    /**
     * 计算显示地图的半径
     */
    private void calculateDistance(){
        try {
            //左上角经纬度
            Point pt = new Point();
            pt.x=0;
            pt.y=0;
            LatLng ll = mBaiDuMap.getProjection().fromScreenLocation(pt);
            //右下角经纬度
            DisplayMetrics dm = new DisplayMetrics();
            getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
            Point pty = new Point();
            pty.x=dm.widthPixels;
            pty.y=0;
            LatLng lly = mBaiDuMap.getProjection().fromScreenLocation(pty);
            MapCurrentDistance = (int) DistanceUtil.getDistance(ll,lly)/2;
        }catch (Exception e){

        }
    }
    /**
     * 仅第一次加载此方法
     * @param isRefresh 是否来自 网点无车辆 刷新
     */
    private void loadInFirst(boolean isRefresh,String member) {
        if (isOpen == false)return;
        isRefreshLoad = isRefresh;
        if (currentLatLng == null)return;
        new LHttpLib().getPickParkingSiteList(member,mContext,  String.valueOf(currentLatLng.longitude),
                String.valueOf(currentLatLng.latitude), String.valueOf(currentDistance),null, new BaseLHttpHandler(mContext, isShowLoading, true) {

                    @Override
                    public void onSuccess(JSONStatus jsonStatus) {
                        super.onSuccess(jsonStatus);
                        isShowLoading = false;
                        if(jsonStatus.data.has("parking_site_list")){
                            JSONArray jsonArray = jsonStatus.data.optJSONArray("parking_site_list");
                            overlayOptionsList = new ArrayList<>();
                            parkingMarkerList = new ArrayList<>();
                            parkingSiteList = new ArrayList<>(); //todo 看是否需要分页加载，看是否需要每次加载出来都新建一个列表集合
                            if(jsonArray != null && jsonArray.length() > 0) {
                                for (int i = 0; i < jsonArray.length(); i++) {
                                    parkingSiteList.add(new ParkingSite().parse(jsonArray.optJSONObject(i)));
                                }
                                parkingMarkerList = parkingSiteList;
                                addMarker();}
                        }else {
                            if (currentDistance == 1000){
                                currentDistance = 2000;
                                loadInFirst(false,"");
                            }else if (currentDistance == 2000){
                                currentDistance = 3000;
                                loadInFirst(false,"");
                            }else if(currentDistance==3000){
                                currentDistance = 4000;
                                loadInFirst(false,"");
                            }else if(currentDistance==4000){
                                currentDistance = 5000;
                                loadInFirst(false,"");
                            }
                        }
                    }
                });
    }
    /**
     * 加载车辆网点数据
     * @param isRefresh 是否来自 网点无车辆 刷新
     */
    private void load(boolean isRefresh,String member) {
        /*if(loadingDialog == null) {
            loadingDialog = new LoadingDialog(mContext, "正在加载");
        }
        if(!loadingDialog.isShowing()) {
            loadingDialog.show();
        }*/
        if (isOpen == false)return;
        isRefreshLoad = isRefresh;
        if (currentLatLng == null)return;
        new LHttpLib().getPickParkingSiteList(member,mContext,  String.valueOf(currentLatLng.longitude),
                String.valueOf(currentLatLng.latitude), String.valueOf(20000),null, new BaseLHttpHandler(mContext, isShowLoading, true) {

                    @Override
                    public void onSuccess(JSONStatus jsonStatus) {
                        super.onSuccess(jsonStatus);
                        isShowLoading = false;
                        JSONObject jsonArray = jsonStatus.data.optJSONObject("lately_parking_site");
                        if(jsonArray!=null&&!jsonArray.toString().equals("")) {
                            overlayOptionsList = new ArrayList<>();
                            parkingMarkerList = new ArrayList<>();
                            parkingSiteList = new ArrayList<>(); //todo 看是否需要分页加载，看是否需要每次加载出来都新建一个列表集合
                            parkingMarkerList.clear();
                            parkingSiteList.clear();
                            for (int i = 0; i < jsonArray.length(); i++) {
                                parkingSiteList.add(new ParkingSite().parse(jsonArray));
                            }
                            parkingMarkerList = parkingSiteList;
                            for (int i = 0; i < parkingSiteList.size(); i++) {
                                if(parkingSiteList.get(i).usable_car_count>=0){
                                    EndLat=new LatLng(parkingSiteList.get(i).latitude_num,parkingSiteList.get(i).longitude_num);
                                    PakeId=parkingSiteList.get(i).parking_site_id;
                                    addMarker();
                                    //return;
                                }
                            }
                            setMyLocationToCenter(new LatLng(bdLocation.getLatitude(),bdLocation.getLongitude()),currentZoom);

                            currentLatLng = new LatLng(bdLocation.getLatitude(),bdLocation.getLongitude());
                            GetMapPath(currentLatLng,EndLat);
                            carPopupWindow= new ParkingSiteCarPopupWindow(mContext,PakeId,String.valueOf(currentLatLng.longitude), String.valueOf(currentLatLng.latitude));
                            carPopupWindow.showAtLocation(getActivity().findViewById(R.id.ac_main), Gravity.BOTTOM,0,0);
                            carPopupWindow.setFocusable(true);
                            //有可用的车辆
                            /*carDialog = new ParkingSiteCarDialog(mContext,PakeId, String.valueOf(currentLatLng.longitude), String.valueOf(currentLatLng.latitude));
                            carDialog.show();
                            carDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                                @Override
                                public void onDismiss(DialogInterface dialog) {
                                    mBaiDuMap.clear();
                                    setMyLocationToCenter(new LatLng(bdLocation.getLatitude(),bdLocation.getLongitude()),currentZoom);

                                    currentLatLng = new LatLng(bdLocation.getLatitude(),bdLocation.getLongitude());
                                    loadAll(false,"");
                                }
                            });*/
                        }else{
                            Toast.makeText(getActivity(), "附近没有可用车辆",
                                    Toast.LENGTH_SHORT).show();
                        }
                        /* if(jsonArray != null && jsonArray.length() >= 0) {
                            parkingMarkerList.clear();
                            parkingSiteList.clear();
                            for (int i = 0; i < jsonArray.length(); i++) {
                                parkingSiteList.add(new ParkingSite().parse(jsonArray.optJSONObject(i)));
                            }
                            parkingMarkerList = parkingSiteList;
                            for (int i = 0; i < parkingSiteList.size(); i++) {
                                if(parkingSiteList.get(i).usable_car_count>=0){
                                    EndLat=new LatLng(parkingSiteList.get(i).latitude_num,parkingSiteList.get(i).longitude_num);
                                    PakeId=parkingSiteList.get(i).parking_site_id;
                                    addMarker();
                                    return;
                                }
                            }
                    }*/
                    }
                });
    }

    /**
     * 仅第一次加载此方法
     * @param isRefresh 是否来自 网点无车辆 刷新
     */
    private void loadAll(boolean isRefresh,String memberid) {
        if (isOpen == false)return;
        isRefreshLoad = isRefresh;
        if (currentLatLng == null)return;
        new LHttpLib().getPickParkingSiteList(memberid,mContext,  String.valueOf(currentLatLng.longitude),
                String.valueOf(currentLatLng.latitude), String.valueOf(MapCurrentDistanceList),null, new BaseLHttpHandler(mContext, isShowLoading, true) {

                    @Override
                    public void onSuccess(JSONStatus jsonStatus) {
                        super.onSuccess(jsonStatus);
                        isShowLoading = false;
                        if(jsonStatus.data.has("parking_site_list")){
                            JSONArray jsonArray = jsonStatus.data.optJSONArray("parking_site_list");
                            overlayOptionsList = new ArrayList<>();
                            parkingMarkerList = new ArrayList<>();
                            parkingSiteList = new ArrayList<>(); //todo 看是否需要分页加载，看是否需要每次加载出来都新建一个列表集合
                            if(jsonArray != null && jsonArray.length() > 0) {
                                for (int i = 0; i < jsonArray.length(); i++) {
                                    parkingSiteList.add(new ParkingSite().parse(jsonArray.optJSONObject(i)));
                                }
                                parkingMarkerList = parkingSiteList;
                                addMarker();}
                        }
                    }
                });
    }
    /** 获取当前定位的城市id，查询是否已开通*/
    void loadLocationOpen(final BDLocation location) {
        //判断当前城市是否开通
        new LHttpLib().getRegionCoordinate(mContext, String.valueOf(location.getLongitude()),
                String.valueOf(location.getLatitude()), new BaseLHttpHandler(mContext, true, true) {

                    @Override
                    public void onSuccess(JSONStatus jsonStatus) {
                        super.onSuccess(jsonStatus);
                        Region region = new Region().parse(jsonStatus.data.optJSONObject("region_info"));
                        //从配置文件中读取 当前 region_id 是否已开通
                        if ("0".equals(region.getIs_open())){
                            isOpen = false;
                            if (promptDialog != null){
                                if (promptDialog.isShowing())
                                    promptDialog.cancel();
                                promptDialog = null;
                            }
                            promptDialog = new PromptDialog(mContext,
                                    getString(R.string.business_not_opened),
                                    getString(R.string.business_not_opened_hint),
                                    "确认",getString(R.string.dialogpic_notice),
                                    new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    promptDialog.dismiss();
                                }
                            });
                            promptDialog.show();
                        }else {
                            isOpen = true;
                            loadAll(false,"");
                        }
                    }
                });
    }




    public ImageLoader imageLoader;
    /************************************** 百度地图相关配置 ⬇️️ *******************************************/
    /** 地图打点*/


    void addMarker() {
//        for (int i = 0; i < parkingSiteList.size(); i++) {
        if (parkingMarkerList == null || parkingMarkerList.size() == 0){
            isFirstLoad = false;
            handler.sendEmptyMessage(MARKER_LOADED);
            return;
        }
        final ParkingSite parkingSite = parkingMarkerList.get(0);
        final View  v = LayoutInflater.from(mContext).inflate(R.layout.item_parking_site_marker, null);
        final ImageView  ivMapParkingSite = (ImageView) v.findViewById(R.id.ivMapParkingSite);
        TextView tvMapUsableCarCount = (TextView) v.findViewById(R.id.tvMapUsableCarCount);
        tvMapUsableCarCount.setText(String.valueOf(parkingSite.usable_car_count));
        tvMapUsableCarCount.setBackgroundResource(parkingSite.usable_car_count > 0 ? R.drawable.bg_site_count_blue_shape : R.drawable.bg_site_count_gray_shape);
        ivMapParkingSite.setBackgroundResource(parkingSite.usable_car_count > 0 ? R.drawable.have_car_shape_bg : R.drawable.have_no_car_shape_bg);
        if (StringUtils.isEmpty(parkingSite.parking_site_image.thumb)){
            MarkerOptions markerOptions = new MarkerOptions();
            markerOptions.position(new LatLng(parkingSite.latitude_num, parkingSite.longitude_num));
            markerOptions.icon(BitmapDescriptorFactory.fromView(v));
            Bundle info = new Bundle();
            info.putSerializable("parkingSite", parkingSite);
            markerOptions.extraInfo(info);
            overlayOptionsList.add(markerOptions);
            if (parkingMarkerList.size() >0)parkingMarkerList.remove(0);
            addMarker();
        }else {
            imageLoader.displayImage(parkingSite.parking_site_image.thumb, ivMapParkingSite,
                    parkingSite.usable_car_count > 0 ? hasCarOptions : noCarOptions, new ImageLoadingListener() {
                        @Override
                        public void onLoadingStarted(String s, View view) {

                        }

                        @Override
                        public void onLoadingFailed(String s, View view, FailReason failReason) {
                            MarkerOptions markerOptions = new MarkerOptions();
                            markerOptions.position(new LatLng(parkingSite.latitude_num, parkingSite.longitude_num));
                            markerOptions.icon(BitmapDescriptorFactory.fromView(v));
                            Bundle info = new Bundle();
                            info.putSerializable("parkingSite", parkingSite);
                            markerOptions.extraInfo(info);
                            overlayOptionsList.add(markerOptions);
                            if (parkingMarkerList.size() >0)parkingMarkerList.remove(0);
                            addMarker();
                        }

                        @Override
                        public void onLoadingComplete(String s, View view, Bitmap bitmap) {
                            MarkerOptions markerOptions = new MarkerOptions();
                            markerOptions.position(new LatLng(parkingSite.latitude_num, parkingSite.longitude_num));
                            markerOptions.icon(BitmapDescriptorFactory.fromView(v));
                            Bundle info = new Bundle();
                            info.putSerializable("parkingSite", parkingSite);
                            markerOptions.extraInfo(info);
                            if (parkingSite.usable_car_count > 0){
                                ivMapParkingSite.setImageBitmap(bitmap);
                            }else {
                                ivMapParkingSite.setImageResource(R.mipmap.ic_map_car_gray);
                            }
                            overlayOptionsList.add(markerOptions);
                            if (parkingMarkerList.size() >0)parkingMarkerList.remove(0);
                            addMarker();
                        }

                        @Override
                        public void onLoadingCancelled(String s, View view) {

                        }
                    });

        }
        //来自刷新某网点的数据
        if (isRefreshLoad == true && parkingSite.parking_site_no.equals(currentRefreshSiteNo)){
            takeCurrentBranch(parkingSite);
        }
    }

    Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case MARKER_LOADED:
                    if(overlayOptionsList != null && overlayOptionsList.size() > 0) {
                        if(!overlayOptionsList.equals(myOverlayManager.getOverlayOptions())) {
                            myOverlayManager.removeFromMap();
                            myOverlayManager.setOverlayOptionsList(overlayOptionsList);
                            myOverlayManager.addToMap();
                            myOverlayManager.zoomToSpan();
                        }
                        if(mBaiDuMap!=null){
                            setMyLocationToCenter(currentLatLng,currentZoom);
                        }
                    }
                    break;
            }
        }
    };

    /** 定位SDK监听函数*/
    public class MyLocationListener implements BDLocationListener {

        @Override
        public void onReceiveLocation(final BDLocation location) {
            // map view 销毁后不在处理新接收的位置
            if (location == null || mMapView == null) {
                return;
            }
            bdLocation = location;
            PreferencesUtils.putString(mContext,"ADR",String.valueOf(bdLocation.getAddrStr()));
            PreferencesUtils.putString(mContext,"LNG",String.valueOf(bdLocation.getLatitude())+":"+String.valueOf(bdLocation.getLongitude()));
            currentLatLng = new LatLng(bdLocation.getLatitude(),bdLocation.getLongitude());

//            if(location.getLocType() == BDLocation.TypeNetWorkLocation) {
//                loadLocationOpen(location);
//            }
            // 构造定位数据
            MyLocationData locData = new MyLocationData.Builder().accuracy(location.getRadius())
                    // 此处设置开发者获取到的方向信息，顺时针0-360
                    .direction(100).latitude(location.getLatitude()).longitude(location.getLongitude()).direction(location.getDirection()).build();

            mBaiDuMap.setMyLocationData(locData); // 设置定位数据
            if (isFirstLoc) {
                isFirstLoc = false;
                LatLng ll = new LatLng(location.getLatitude(), location.getLongitude());
                MapStatus.Builder builder = new MapStatus.Builder();
                builder.target(ll).zoom(18);
                mBaiDuMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
                //第一次进入主界面加载数据
                loadLocationOpen(location);
            }
            mBaiDuMap.setOnMapTouchListener(new BaiduMap.OnMapTouchListener() {
                @Override
                public void onTouch(MotionEvent motionEvent) {
                    popDismiss();
                }
            });
            mBaiDuMap.setOnMapClickListener(new BaiduMap.OnMapClickListener(){
                @Override
                public void onMapClick(LatLng latLng) {
                    popDismiss();
                    mBaiDuMap.clear();
                    setMyLocationToCenter(new LatLng(bdLocation.getLatitude(),bdLocation.getLongitude()),currentZoom);
                    currentLatLng = new LatLng(bdLocation.getLatitude(),bdLocation.getLongitude());
                    loadAll(false,"");}

                @Override
                public boolean onMapPoiClick(MapPoi mapPoi) {
                    return false;
                }
            });
            mBaiDuMap.setOnMapLoadedCallback(new BaiduMap.OnMapLoadedCallback() {
                @Override
                public void onMapLoaded() {
                    myOverlayManager = new MyOverlayManager(mBaiDuMap);
                }
            });
            mBaiDuMap.setOnMapStatusChangeListener(new BaiduMap.OnMapStatusChangeListener() {
                @Override
                public void onMapStatusChangeStart(MapStatus mapStatus) {

                }
                @Override
                public void onMapStatusChangeStart(MapStatus arg0, int arg1) {
                    // TODO Auto-generated method stub

                }
                @Override
                public void onMapStatusChange(MapStatus mapStatus) {
                    /**
                     * 地图状态改变结束
                     * @param status 地图状态改变结束后的地图状态
                     */
                    if (!isFirstLoad){
                        calculateDistance();
                    }
                }

                @Override
                public void onMapStatusChangeFinish(MapStatus mapStatus) {
                   /* //如果大于17缩放等级，相当于是放大到500米 |...| 20米，距离太小，不做处理
                    currentZoom = mapStatus.zoom;
                    Log.e(TAG, "当前zoom  " + currentZoom);
                    currentLatLng = mBaiDuMap.getMapStatus().target;
                    Log.e(TAG, "current location  " + currentLatLng.latitude+"   "+bdLocation.getLatitude());
                    if (!isFirstLoad){
                        load(false);
                    }*/
                }
            });
            logLocationData(location);
        }
        public void onReceivePoi(BDLocation poiLocation) {
        }
    }



    /** 初始化地图*/
    private void initBaiDuMap() {
        mBaiDuMap = mMapView.getMap();
        //初始化默认西安中心点坐标
        Double lat = 108.953098279;
        Double lng = 34.2777998978;
        LatLng latLng = new LatLng(lat, lng);
        setMyLocationToCenter(latLng,currentZoom);

        // LocationMode.COMPASS 罗盘 FOLLOWING 跟随 NORMAL 普通
//        mBaiDuMap.setMyLocationConfigeration(
//        new MyLocationConfiguration(MyLocationConfiguration.LocationMode.FOLLOWING, true, null)); //传入null当前定位是默认蓝色小点图标
        // 开启定位图层
        mBaiDuMap.setMyLocationEnabled(true);
        // TODO: 2017/6/16 暂时注释
        // 开启交通路况图
//        mBaiDuMap.setTrafficEnabled(isOpenRoadStatus);
        // 定位初始化
        mLocClient = new LocationClient(mContext);
        mLocClient.registerLocationListener(new MyLocationListener());
        initLocation();
        mLocClient.start();
        myOverlayManager = new MyOverlayManager(mBaiDuMap);
        mBaiDuMap.setOnMarkerClickListener(new BaiduMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker) {
                Bundle info = marker.getExtraInfo();
                ParkingSite parkingSite = (ParkingSite) info.getSerializable("parkingSite");
                takeCurrentBranch(parkingSite);
                return true;
            }
        });
    }

    /** 初始化定位设置*/
    private void initLocation(){
        // LocationClientOption option = new LocationClientOption();
        LocationClientOption option = new LocationClientOption();
        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        //可选，默认高精度，设置定位模式，高精度，低功耗，仅设备
        option.setCoorType("bd09ll");
        //可选，默认gcj02，设置返回的定位结果坐标系
        int span = 0;//1000 //todo 根据实际情况是否关闭定位，暂时只定位一次
        //可选，默认0，即仅定位一次，设置发起定位请求的间隔需要大于等于1000ms才是有效的
        option.setScanSpan(span);
        //可选，设置是否需要地址信息，默认不需要
        option.setIsNeedAddress(true);
        //可选，默认false,设置是否使用gps
        option.setOpenGps(true);
        //可选，默认false，设置是否当GPS有效时按照1S/1次频率输出GPS结果
        option.setLocationNotify(true);
        //可选，默认false，设置是否需要位置语义化结果，可以在BDLocation.getLocationDescribe里得到，结果类似于“在北京天安门附近”
        option.setIsNeedLocationDescribe(true);
        //可选，默认false，设置是否需要POI结果，可以在BDLocation.getPoiList里得到
        option.setIsNeedLocationPoiList(true);
        //可选，默认true，定位SDK内部是一个SERVICE，并放到了独立进程，设置是否在stop的时候杀死这个进程，默认不杀死
        option.setIgnoreKillProcess(false);
        //可选，默认false，设置是否收集CRASH信息，默认收集
        option.SetIgnoreCacheException(false);
        //可选，默认false，设置是否需要过滤GPS仿真结果，默认需要
        option.setEnableSimulateGps(false);
        // 在网络定位中，获取手机机头所指的方向
        option.setNeedDeviceDirect(true);
        mLocClient.setLocOption(option);
    }

    @Override
    public void onPause() {
        mMapView.onPause();
        if(mBaiDuMap!=null){
        mBaiDuMap.clear();}
        // setMyLocationToCenter(new LatLng(bdLocation.getLatitude(),bdLocation.getLongitude()));
        // currentLatLng = new LatLng(bdLocation.getLatitude(),bdLocation.getLongitude());
        loadAll(false,"");
        isForeground = false;
        super.onPause();
    }

    @Override
    public void onResume() {
        mMapView.onResume();
        isForeground = true;
        super.onResume();
        //获取用户信息
        //刷新页面
        DataLoadUtil.refreshMemberData(mContext, new MemberCallBack() {
            @Override
            public void getMember(Member m) {
                member = m;
                setView();
            }
        });
    }
    //显示弹窗
    void setView() {
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if(member.member_auth_info.member_auth_status.equals("0")) {
//                    UserAuth.setVisibility(View.VISIBLE);
                }
                if(member.member_deposit_info.is_deposit.equals("0")) {
//                    UserAuth.setVisibility(View.VISIBLE);
                }
                if(member.member_deposit_info.is_deposit.equals("2")) {
//                    UserAuth.setVisibility(View.VISIBLE);
                }
                //资质认证
                if(member.member_auth_info.member_auth_status.equals("1")) {
//                    UserAuth.setVisibility(View.GONE);
                }
                //保证金
                if(member.member_deposit_info.is_deposit.equals("1")) {
//                    UserAuth.setVisibility(View.GONE);
                }
            }
        });
    }
    @Override
    public void onStart() {
        super.onStart();
        DataLoadUtil.refreshMemberData(mContext);
    }
    /**
     *获取当前是否有未完成订单
     */
    private void loadNoFinishOrder(){
        DataLoadUtil.getDeviceNotifyInfo(mContext, false, new DeviceOrderInfoCallBack() {
            @Override
            public void getCallBack(DeviceOrderInfo deviceOrderInfo) {
                // TODO: 2017/8/4 获取当前未完成订单
                device_notify_key=deviceOrderInfo.device_notify_key;
                String car_order_no = "";
                switch (deviceOrderInfo.device_notify_key){
                    case "car_subscribe"://订单预约中
                        prompt("当前有正在预约的订单,请切换");
                        car_order_no = deviceOrderInfo.device_notify_value.optString("car_order_no");
                        FoundCarActivity.startAction(mContext,"",car_order_no,false);
                        break;
                    case "car_use"://订单进行中
                        prompt("当前有正在进行的订单,请切换");
                        car_order_no = deviceOrderInfo.device_notify_value.optString("car_order_no");
                        FoundCarActivity.startAction(mContext,"",car_order_no,true);
                        break;
                    case "car_pending_payment"://订单未支付
                        prompt("您有一笔未支付订单，请先支付…");
                        car_order_no = deviceOrderInfo.device_notify_value.optString("car_order_no");
                        OrderDetailActivity.startAction(mContext,car_order_no);
                        break;
                    case "member_deposit_pay"://您的押金不足
                        //押金余额跳转
                        prompt("您的押金需要补缴…");
                        startActivity(new Intent(mContext, DepositBalanceActivity.class));
                        break;
                    case "member_other_pay"://其他费用未缴纳
                        //其他费用单号
                        prompt("您的其他费用未缴纳…");
                        device_notify_key_order_no=deviceOrderInfo.device_notify_value.optString("car_order_no");
                        car_order_no = deviceOrderInfo.device_notify_value.optString("car_order_no");
                        OrderDetailActivity.startAction(mContext,car_order_no);
                        break;
                }
            }
        });
    }
    @Override
    public void onDestroy() {
        // 退出时销毁定位
        mLocClient.stop();
        // 关闭定位图层
        mBaiDuMap.setMyLocationEnabled(false);
        mBaiDuMap.clear();
        mMapView.onDestroy();
        mMapView = null;
        mBaiDuMap = null;
        popDismiss();
        super.onDestroy();
    }

    private class MyOverlayManager extends OverlayManager {

        private List<OverlayOptions> overlayOptionsList;

        public void setOverlayOptionsList(List<OverlayOptions> overlayOptionsList) {
            this.overlayOptionsList = overlayOptionsList;
        }

        public MyOverlayManager(BaiduMap baiduMap) {
            super(baiduMap);
        }

        @Override
        public List<OverlayOptions> getOverlayOptions() {
            return overlayOptionsList;
        }

        @Override
        public boolean onMarkerClick(Marker marker) {
            return false;
        }

        @Override
        public boolean onPolylineClick(Polyline polyline) {
            return false;
        }
    }
    /************************************** 百度地图相关配置 ⬆️ *******************************************/

    /** 刷新取车点*/
    public void refreshParkingSites(String parking_site_no) {
        currentRefreshSiteNo = parking_site_no;
        loadAll(true,"");
    }



    private void logLocationData(BDLocation location) {
        //获取定位结果
        StringBuffer sb = new StringBuffer(256);
        sb.append("time : ");
        sb.append(location.getTime());    //获取定位时间
        sb.append("\nerror code|location type : ");
        sb.append(location.getLocType());    //获取类型类型
        sb.append("\nlatitude : ");
        sb.append(location.getLatitude());    //获取纬度信息
        sb.append("\nlontitude : ");
        sb.append(location.getLongitude());    //获取经度信息
        sb.append("\nradius : ");
        sb.append(location.getRadius());    //获取定位精准度
        if (location.getLocType() == BDLocation.TypeGpsLocation) {
            // GPS定位结果
            sb.append("\nspeed : ");
            sb.append(location.getSpeed());    // 单位：公里每小时
            sb.append("\nsatellite : ");
            sb.append(location.getSatelliteNumber());    //获取卫星数
            sb.append("\nheight : ");
            sb.append(location.getAltitude());    //获取海拔高度信息，单位米
            sb.append("\ndirection : ");
            sb.append(location.getDirection());    //获取方向信息，单位度
            sb.append("\naddr : ");
            sb.append(location.getAddrStr());    //获取地址信息
            sb.append("\ndescribe : ");
            sb.append("gps定位成功");
        } else if (location.getLocType() == BDLocation.TypeNetWorkLocation) {
            // 网络定位结果
            sb.append("\naddr : ");
            sb.append(location.getAddrStr());    //获取地址信息
            sb.append("\noperationers : ");
            sb.append(location.getOperators());    //获取运营商信息
            sb.append("\ndirection : ");
            sb.append(location.getDirection()); //获得手机方向，范围【0-360】，手机上部正朝向北的方向为0°方向
            sb.append("\ndescribe : ");
            sb.append("网络定位成功");
        } else if (location.getLocType() == BDLocation.TypeOffLineLocation) {
            // 离线定位结果
            sb.append("\ndescribe : ");
            sb.append("离线定位成功，离线定位结果也是有效的");
        } else if (location.getLocType() == BDLocation.TypeServerError) {
            sb.append("\ndescribe : ");
            sb.append("服务端网络定位失败，可以反馈IMEI号和大体定位时间到loc-bugs@baidu.com，会有人追查原因");
        } else if (location.getLocType() == BDLocation.TypeNetWorkException) {
            sb.append("\ndescribe : ");
            sb.append("网络不同导致定位失败，请检查网络是否通畅");
        } else if (location.getLocType() == BDLocation.TypeCriteriaException) {
            sb.append("\ndescribe : ");
            sb.append("无法获取有效定位依据导致定位失败，一般是由于手机的原因，处于飞行模式下一般会造成这种结果，可以试着重启手机");
        }
        sb.append("\nlocationdescribe : ");
        sb.append(location.getLocationDescribe());    //位置语义化信息
        List<Poi> list = location.getPoiList();    // POI数据
        if (list != null) {
            sb.append("\npoilist size = : ");
            sb.append(list.size());
            for (Poi p : list) {
                sb.append("\npoi= : ");
                sb.append(p.getId() + " " + p.getName() + " " + p.getRank());
            }
        }
    }

    /**
     * 当前网点车辆信息
     * @param parkingSite
     */
    public void takeCurrentBranch(ParkingSite parkingSite){
        if (parkingSite == null)return;
        if(parkingSite.usable_car_count > 0) {
            //有可用的车辆
            if(device_notify_key!=null){
                if(device_notify_key.equals("member_other_pay")) {
                    OrderDetailActivity.startAction(mContext,device_notify_key_order_no);
                }else{
                   Log.e("tag","site = "+ parkingSite.parking_site_id+"..."+String.valueOf(currentLatLng.longitude)+"..."+String.valueOf(currentLatLng.latitude));
                    showPop(parkingSite);
                }
            }else{
                Log.e("tag","site2 = "+ parkingSite.parking_site_id+"..."+String.valueOf(currentLatLng.longitude)+"..."+String.valueOf(currentLatLng.latitude));
                     showPop(parkingSite);
            }
        } else {
            //无可用的车辆
            ParkingSiteNoCarDialog noCarDialog = new ParkingSiteNoCarDialog(mContext,parkingSite.parking_site_no);
            noCarDialog.show();
        }
    }
    /**显示车辆列表弹窗*/
    private void showPop(ParkingSite parkingSite) {
        popDismiss();
        if(carPopupWindow==null){
            Log.e("tag","新弹窗");
            carPopupWindow= new ParkingSiteCarPopupWindow(mContext, parkingSite.parking_site_id,String.valueOf(currentLatLng.longitude), String.valueOf(currentLatLng.latitude));
            carPopupWindow.showAtLocation(getActivity().findViewById(R.id.ac_main), Gravity.BOTTOM,0,0);
            carPopupWindow.setFocusable(true);
        }
    }

    /************************************************ 版本更新 starting **************************************************/
    private void updateVersion(){
        DataLoadUtil.getConfig(mContext, new ConfigCallBack() {
            @Override
            public void getConfig() {
                FinalDb finalDb = FinalDb.create(mContext);
                List<ClientVersion> client = finalDb.findAll(ClientVersion.class);
                if (client != null && client.size() >0){
                    doUpdate(client.get(0));
                }
            }
        });
    }
    private PromptDialog updatePromptDialog;

    private void doUpdate(ClientVersion clientVersion) {
        if("1".equals(clientVersion.need_update)) {
            getUpdatePromptDialog(clientVersion).show();
        } else {
            if("1".equals(clientVersion.has_update) && "1".equals(clientVersion.is_tips)) {
                getUpdatePromptDialog(clientVersion).show();
            } else {
//                switchPage();
            }
        }
    }

    private PromptDialog getUpdatePromptDialog(final ClientVersion clientVersion) {
        if("1".equals(clientVersion.need_update)) {
            //强制更新，一个按钮&隐藏取消按钮
            updatePromptDialog = new PromptDialog(mContext, getString(R.string.notice), clientVersion.tips_content,
                    getString(R.string.update_now), getString(R.string.dialogpic_notice), new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    updatePromptDialog.dismiss();
                    download(clientVersion.download_type, clientVersion.download_url);
                }
            });
        } else {
            updatePromptDialog = new PromptDialog(mContext, getString(R.string.notice), clientVersion.tips_content, getString(R.string.update_now),
                    getString(R.string.update_later), getString(R.string.dialogpic_notice), new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    updatePromptDialog.dismiss();
                    download(clientVersion.download_type, clientVersion.download_url);
                }
            }, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    updatePromptDialog.dismiss();
                }
            }, false);
        }
        return updatePromptDialog;
    }

    private void download(String type, String download_url) {
        if(type.equals(Constants.DOWNLOAD_TYPE_WEB)) {
            downloadWeb(download_url);
        }
        if(type.equals(Constants.DOWNLOAD_TYPE_APK)) {
            downloadApk(download_url);
        }
    }

    private void downloadWeb(String url) {
        Uri uri = Uri.parse(url);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);
    }

    private void downloadApk(String url) {
        final ProgressDialog downloadDialog = new ProgressDialog(mContext, R.style.LightDialog);
        downloadDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        downloadDialog.setTitle("下载中");
        downloadDialog.setIndeterminate(false);
        downloadDialog.setCancelable(false);
        downloadDialog.setCanceledOnTouchOutside(false);
        downloadDialog.show();
        new FinalHttp().download(url, Constants.APK_TARGET, new AjaxCallBack<File>() {
            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                super.onFailure(t, errorNo, strMsg);
                prompt("出错：" + strMsg);
            }

            @Override
            public void onLoading(long count, long current) {
                super.onLoading(count, current);
                int progress;
                if (current != count && current != 0) {
                    progress = (int) (current / (float) count * 100);
                } else {
                    progress = 100;
                }
                downloadDialog.setProgress(progress);
            }

            @Override
            public void onStart() {
                super.onStart();
            }

            @Override
            public void onSuccess(File t) {
                super.onSuccess(t);
                downloadDialog.dismiss();
                PackageUtil.installNormal(mContext, Constants.APK_TARGET);
            }
        });
    }
    /************************************************ 版本更新 ending **************************************************/

    //------------------规划路线-------------------
    public void GetMapPath(LatLng StartLat,LatLng EndLat){
        PlanNode startPlanNode=PlanNode.withLocation(StartLat);
        PlanNode endPlanNode=PlanNode.withLocation(EndLat);
        mSearch.bikingSearch((new BikingRoutePlanOption())
                .from(startPlanNode).to(endPlanNode));
    }
    @Override
    public void onGetWalkingRouteResult(WalkingRouteResult result) {
    }
    @Override
    public void onGetIndoorRouteResult(IndoorRouteResult indoorRouteResult) {
    }
    @Override
    public void onGetTransitRouteResult(TransitRouteResult result) {
    }
    @Override
    public void onGetMassTransitRouteResult(MassTransitRouteResult result) {
    }
    @Override
    public void onGetDrivingRouteResult(DrivingRouteResult result) {
    }
    @Override
    public void onGetBikingRouteResult(BikingRouteResult result) {
        if (result == null || result.error !=   SearchResult.ERRORNO.NO_ERROR) {
            Toast.makeText(mContext, "抱歉，未找到结果", Toast.LENGTH_SHORT).show();
        }
        if (result.error == SearchResult.ERRORNO.AMBIGUOUS_ROURE_ADDR) {
            // 起终点或途经点地址有岐义，通过以下接口获取建议查询信息
            result.getSuggestAddrInfo();
            return;
        }
        if (result.getRouteLines().size() >= 1) {
                        /*BikingRouteOverlay overlay = new BikingRouteOverlay(mBaiDuMap);
                        mBaiDuMap.setOnMarkerClickListener(overlay);
                        overlay.setData(bikingRouteResult.getRouteLines().get(0));
                        overlay.addToMap();
                        overlay.zoomToSpan();*/
            //-----------------------
            BikingRouteOverlay overlay = new BikingRouteOverlay(mBaiDuMap);
            mBaiDuMap.setOnMarkerClickListener(overlay);
            overlay.setData(result.getRouteLines().get(0));
            overlay.addToMap();
            overlay.zoomToSpan();
        } else {
            return;
        }
    }
}
